/*******************************************************************************
 * Copyright © 2017 FriendStar.Framework 版权所有
 * Author: HYF
 * Description: FriendStar快速开发平台
 * Website：http://www.FriendStar.cn
*********************************************************************************/
using FriendStar.Code;
using FriendStar.Data;
using FriendStar.Domain.Entity.WareHouse;
using FriendStar.Domain.IRepository.WareHouse;
using FriendStar.Repository.Infrastructure;
using System.Collections.Generic;

namespace FriendStar.Repository.WareHouse
{
    public class CPK_21_CC_StoStorageCardRepository : RepositoryBase<CPK_21_CC_StoStorageCardEntity>, ICPK_21_CC_StoStorageCardRepository
    {
        public void SaveCC_StoStorageCard(List<string> list)
        {
            string UseUnit = Configs.GetValue("UseUnit");
            string FFacNum = Configs.GetValue("FactoryFlag");
            string FAccountDate = GetDocumentNum.GetNum(UseUnit, FFacNum, "台账日期成品", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
            using (var db = new RepositoryBase().BeginTrans())
            {
                try
                {
                    #region 执行
                    foreach (string item in list)
                    {
                        var obj = new { FRegisterID=item, AccountDate= FAccountDate, FAuditingBy= OperatorProvider.Provider.GetCurrent().UserName };
                        db.ExecuteStoredProcedure<string>("Pro_CPK_42_MX_StoCPKListAcco", obj);
                    }
                    var pars = new { UseUnit = UseUnit, FFacNum = FFacNum, FCreateByNO = OperatorProvider.Provider.GetCurrent().UserCode, UserName = OperatorProvider.Provider.GetCurrent().UserName, FAccountDate = FAccountDate };
                    db.ExecuteStoredProcedure<string>("Pro_StoStorageCard", pars);
                    db.Commit();
                    #endregion 执行
                }
                catch (System.Exception ex)
                {
                    db.RollBack();
                    throw ex;
                }
            }
        }

        public void DeleteCC_StoStorageCard(List<string> list)
        {
            using (var db = new RepositoryBase().BeginTrans())
            {
                try
                {
                    #region 执行
                    foreach (string item in list)
                    {
                        var obj = new { FRegisterID = item };
                        db.ExecuteStoredProcedure<string>("Pro_DeleteStoStorageCard", obj);
                    }
                    db.Commit();
                    #endregion 执行
                }
                catch (System.Exception ex)
                {
                    db.RollBack();
                    throw ex;
                }
            }
        }
    }
}
